var index;
$(function(){
  init();
  layui.use(['upload','layer'], function(){
    var upload = layui.upload;
    var layer = layui.layer;
    upload.render({
      elem: '#test2'
      ,url: '/uploadSystemFile.do'
      ,multiple: true
      ,size: 10240 //限制文件大小，单位 KB
      ,accept: 'file'
      ,exts: 'jpg|jpeg|png|bmp|'
      ,number: 5
      ,before: function(obj){
        layer.load(); //上传loading
      }
      ,done: function(res){
        layer.closeAll('loading');
        window.location.href = "systemfile.html";
      }
    });
  });

  $("#contentId").on("click",".sysKitClass",function(){
    var id = $(this).attr("kitId");
    window.open("/showSysImage.do?id=" + id);
  });

  $.ajax({
    type : "get",
    url : "getLoginInfo.do",
    success : function(v) {
      if(v.roleId == -1){
        $("#test2").css("display","");
      }else {
        $("#test2").css("display","none");
      }
    }
  });


});

function init() {
  $.ajax({
    type: "get",
    url: "getSysKitListCount.do",
    success: function (data) {
      layui.use(['laypage', 'layer'], function() {
        var laypage = layui.laypage
            , layer = layui.layer;
        //总页数大于页码总数
        laypage.render({
          elem: 'demo1'
          , count: data //数据总数
          , limit:18
          , jump: function (obj) {
            var page = obj.curr;
            $.ajax({
              type: "get",
              url: "getSysKitList.do",
              data:{"page" : page,
                "limit" : obj.limit},
              success: function (data1) {
                var html = "";
                $.each(data1,function (index,item) {
                  html+='<p style="cursor: pointer;">'+ (index + 1) +'&nbsp;、&nbsp;<span class="sysKitClass" kitId="'+item.id+'" style="text-decoration:underline;">'+item.fileName+ '</span></p>';
                });
                if(html == ""){
                  html = "<p>无</p>";
                }
                $("#contentId").html(html);
              }
            });
          }
        });
      });
    }
  });
}
